package xyz.weizhi.tanhua.appserver.controller;

import io.jsonwebtoken.Claims;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import xyz.weizhi.commons.utils.JwtUtils;
import xyz.weizhi.tanhua.appserver.interceptor.UserHolder;
import xyz.weizhi.tanhua.appserver.service.UserInfoService;
import xyz.weizhi.tanhua.appserver.service.UserService;
import xyz.weizhi.tanhua.dubbo.api.UserInfoApi;
import xyz.weizhi.tanhua.model.domain.UserInfo;
import xyz.weizhi.tanhua.model.vo.UserInfoVo;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Author milian
 * @Date 2021/10/22 0022 18:51
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;
    /*
        保存用户信息
     */
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo, @RequestHeader("Authorization") String token){
        userInfo.setId(UserHolder.getId());
        userInfoService.save(userInfo);
        return ResponseEntity.ok(null);
    }
    /*
        上传用户头像
     */
    @PostMapping("/loginReginfo/head")
    public ResponseEntity headUpload(MultipartFile headPhoto,@RequestHeader("Authorization") String token) throws Exception {
        userInfoService.uploadHead(headPhoto,UserHolder.getId());
        return ResponseEntity.ok(null);
    }

}
